package com.fengling.service.impl;

import com.fengling.aop.MyAop;
import com.fengling.mapper.DeptMapper;
import com.fengling.mapper.EmpMapper;
import com.fengling.pojo.Dept;
import com.fengling.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;
import java.util.List;

@Service
@Transactional(rollbackFor = Exception.class)

public class DeptServiceImpl implements DeptService {


    @Autowired
    private DeptMapper deptMapper;
    @Autowired
    private EmpMapper empMapper;


    @Override

    public List<Dept> select() {
        List<Dept> deptList= deptMapper.selectDept();
        return deptList;


    }

    @Override
    @MyAop
    public void delete(Integer id) throws Exception {

        deptMapper.deleteDept(id);
        /*if(true){
            throw new Exception("错错错~");

        }*/

        empMapper.deleteById(id);


    }

    @Override
    public void insert(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());
        deptMapper.insertDept(dept);
    }

    @Override
    @MyAop
    public Dept find(Integer id) {
        return deptMapper.find(id);
    }

    @Override
    public void changeById(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.changeById(dept);

    }

}
